package leetcode.editor.cn.q1_300.q150;

/**
 * 没看答案，写得太复杂了，看每个数能拆分出多少个 5，每个 5 都是一个结尾的 0
 * 但是效率很低
 *
 * @author qidi
 * @date 2022-02-11 09:34:01
 */
class Q0172_FactorialTrailingZeroes {

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int trailingZeroes(int n) {
            if (n < 5) return 0;

            int ans = 0;

            for (int i = 1; i <= n; i++) {
                if (i % 5 != 0) continue;
                int tmp = i;
                int cur = 0;
                while (tmp % 5 == 0) {
                    cur++;
                    tmp /= 5;
                }
                ans += cur;
            }

            return ans;
        }
    }

    //leetcode submit region end(Prohibit modification and deletion)
    public static void main(String[] args) {
        Solution solution = new Q0172_FactorialTrailingZeroes().new Solution();
        solution.trailingZeroes(10);
        for (int i = 1; i <= 100; i++) {
            System.out.println(i + "\t" + solution.trailingZeroes(i));
        }
    }
}